function Quilt() {
  this.canvas = document.getElementById("canvas");
  var img = new Image();
  img.src = 'test.jpg';
  this.canvas.width = img.width;
  this.canvas.height = img.height;
  this.width = img.width;
  this.height = img.height;
  this.ctx = this.canvas.getContext("2d");
  this.canvas.onmousedown = func(this, this.foo, ['a','b']);
  this.canvas.onmouseup = function() { alert('up'); }
}

Quilt.prototype.foo = function(a, b) {
  alert(a+','+b);
}

Quilt.prototype.scale = function(w, h) {
  this.ctx.scale(w, h);
}

Quilt.prototype.checkers = function() {
  var num = 10;
  var w = this.width / num, h = this.height / num;
  var toggle = true;
  var ctx = this.ctx;
  for (var x = 0; x < this.width; x += w) {
    for (var y = 0; y < this.height; y += h) {
      if (toggle)
        ctx.fillRect(x, y, w, h);
      toggle = !toggle;
    }
  }
}

Quilt.prototype.border = function() {
  this.ctx.strokeRect(0, 0, this.width, this.height);
}
 
function init() {
  var quilt = new Quilt();
  quilt.scale(0.1, 0.25);
  quilt.checkers();
  quilt.border();
}
